package com.zz.parkingsystem.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zz.parkingsystem.dto.SectionDTO;
import com.zz.parkingsystem.entity.Section;
import com.zz.parkingsystem.mapper.InspectorMapper;
import com.zz.parkingsystem.mapper.SectionMapper;
import com.zz.parkingsystem.service.SectionService;
import com.zz.parkingsystem.vo.PageResult;
import com.zz.parkingsystem.vo.SectionMessageVO;
import org.springframework.stereotype.Service;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zz.parkingsystem.entity.Section;
import com.zz.parkingsystem.mapper.SectionMapper;
import com.zz.parkingsystem.service.SectionService;
import com.zz.parkingsystem.vo.SectionAndParkingVo;
import javax.annotation.Resource;
import java.util.List;
/**
 * @author wangyuxiang
 */
@Service
public class SectionServiceImpl implements SectionService {

    @Resource
    private SectionMapper sectionMapper;

    @Resource
    private InspectorMapper inspectorMapper;


    @Override
    public PageResult queryAllSectionMessage(SectionDTO sectionDTO) {

        Integer pageIndex = sectionDTO.getPageIndex();
        Integer pageSize = sectionDTO.getPageSize();
        //查询数据
        PageHelper.startPage(pageIndex, pageSize);
        List<SectionMessageVO> list = sectionMapper.queryAllSectionMessage(sectionDTO);
        PageInfo pageInfo = new PageInfo(list);
        PageHelper.clearPage();
        //返回一个自定义分页结果
        PageResult pageResult = new PageResult();
        pageResult.setPageIndex(pageIndex);
        pageResult.setPageSize(pageSize);
        pageResult.setPages(pageInfo.getPages());
        pageResult.setTotal((int) pageInfo.getTotal());
        pageResult.setList(list);
        return pageResult;
    }

    @Override
    public List queryAllIns() {
        return inspectorMapper.queryAllIns();
    }

    @Override
    public int addSection(SectionDTO sectionDTO) {
        Section section = new Section();
        section.setInsId(sectionDTO.getInsId());
        section.setReservedVar(sectionDTO.getTr());
        section.setSecName(sectionDTO.getSecName());
        section.setSecSpaceCount(sectionDTO.getSecSpaceCount());
        section.setStagyId(1);
        return sectionMapper.insertSelective(section);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return sectionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Section record) {
        return sectionMapper.insert(record);
    }

    @Override
    public int insertSelective(Section record) {
        return sectionMapper.insertSelective(record);
    }

    @Override
    public Section selectByPrimaryKey(Long id) {
        return sectionMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Section record) {
        return sectionMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Section record) {
        return sectionMapper.updateByPrimaryKey(record);
    }

    @Override
    public List getselAllSection() {
        return sectionMapper.selAllSection();
    }

    @Override
    public int getselectByPrimarybySecname(String secname) {
        return sectionMapper.selectByPrimarybySecname(secname);
    }

    @Override
    public int getselectByPrimarybyBusy(String secname) {
        return sectionMapper.selectByPrimarybyBusy(secname);
    }

    @Override
    public int getselectByPrimarybyNotBusy(String secname) {
        return sectionMapper.selectByPrimarybyNotBusy(secname);
    }

    @Override
    public List getselectByPrimarybySecnameShow(String secname) {
        return sectionMapper.selectByPrimarybySecnameShow(secname);
    }

    @Override
    public List getselectByPrimarybyBusyShow(String secname) {
        return sectionMapper.selectByPrimarybyBusyShow(secname);
    }

    @Override
    public List<SectionAndParkingVo> getselectByPrimarybyNotBusyShow(String secname) {
        return sectionMapper.selectByPrimarybyNotBusyShow(secname);
    }

    @Override
    public Section getselectByPrimaryKey(Long id) {
        return sectionMapper.selectByPrimaryKey(id);
    }


}